home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 7 / Engine / Engine.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-10-01  |  5.0 KB  |  141 lines

  1. //-----------------------------------------------------------------------------
  2. // The primary engine header file. This file links the entire engine together
  3. // and is the only header file that needs to be included in any project using
  4. // the engine.
  5. //
  6. // Programming a Multiplayer First Person Shooter in DirectX
  7. // Copyright (c) 2004 Vaughan Young
  8. //-----------------------------------------------------------------------------
  9. #ifndef ENGINE_H
  10. #define ENGINE_H
  11.  
  12. //-----------------------------------------------------------------------------
  13. // DirectInput Version Define
  14. //-----------------------------------------------------------------------------
  15. #define DIRECTINPUT_VERSION 0x0800
  16.  
  17. //-----------------------------------------------------------------------------
  18. // System Includes
  19. //-----------------------------------------------------------------------------
  20. #include <stdio.h>
  21. #include <tchar.h>
  22. #include <windowsx.h>
  23.  
  24. //-----------------------------------------------------------------------------
  25. // DirectX Includes
  26. //-----------------------------------------------------------------------------
  27. #include <d3dx9.h>
  28. #include <dinput.h>
  29. #include <dplay8.h>
  30. #include <dmusici.h>
  31.  
  32. //-----------------------------------------------------------------------------
  33. // Macros
  34. //-----------------------------------------------------------------------------
  35. #define SAFE_DELETE( p )       { if( p ) { delete ( p );     ( p ) = NULL; } }
  36. #define SAFE_DELETE_ARRAY( p ) { if( p ) { delete[] ( p );   ( p ) = NULL; } }
  37. #define SAFE_RELEASE( p )      { if( p ) { ( p )->Release(); ( p ) = NULL; } }
  38.  
  39. //-----------------------------------------------------------------------------
  40. // Engine Includes
  41. //-----------------------------------------------------------------------------
  42. #include "Resource.h"
  43. #include "LinkedList.h"
  44. #include "ResourceManagement.h"
  45. #include "Geometry.h"
  46. #include "Font.h"
  47. #include "Scripting.h"
  48. #include "DeviceEnumeration.h"
  49. #include "Input.h"
  50. #include "Network.h"
  51. #include "SoundSystem.h"
  52. #include "State.h"
  53.  
  54. //-----------------------------------------------------------------------------
  55. // Engine Setup Structure
  56. //-----------------------------------------------------------------------------
  57. struct EngineSetup
  58. {
  59.     HINSTANCE instance; // Application instance handle.
  60.     GUID guid; // Application GUID.
  61.     char *name; // Name of the application.
  62.     float scale; // Unit scale in meters/unit.
  63.     unsigned char totalBackBuffers; // Number of back buffers to use.
  64.     void (*HandleNetworkMessage)( ReceivedMessage *msg ); // Network message handler.
  65.     void (*StateSetup)(); // State setup function.
  66.  
  67.     //-------------------------------------------------------------------------
  68.     // The engine setup structure constructor.
  69.     //-------------------------------------------------------------------------
  70.     EngineSetup()
  71.     {
  72.         GUID defaultGUID = { 0x24215591, 0x24c0, 0x4316, { 0xb5, 0xb2, 0x67, 0x98, 0x2c, 0xb3, 0x82, 0x54 } };
  73.  
  74.         instance = NULL;
  75.         guid = defaultGUID;
  76.         name = "Application";
  77.         scale = 1.0f;
  78.         totalBackBuffers = 1;
  79.         HandleNetworkMessage = NULL;
  80.         StateSetup = NULL;
  81.     }
  82. };
  83.  
  84. //-----------------------------------------------------------------------------
  85. // Engine Class
  86. //-----------------------------------------------------------------------------
  87. class Engine
  88. {
  89. public:
  90.     Engine( EngineSetup *setup = NULL );
  91.     virtual ~Engine();
  92.  
  93.     void Run();
  94.  
  95.     HWND GetWindow();
  96.     void SetDeactiveFlag( bool deactive );
  97.  
  98.     float GetScale();
  99.     IDirect3DDevice9 *GetDevice();
  100.     D3DDISPLAYMODE *GetDisplayMode();
  101.     ID3DXSprite *GetSprite();
  102.  
  103.     void AddState( State *state, bool change = true );
  104.     void RemoveState( State *state );
  105.     void ChangeState( unsigned long id );
  106.     State *GetCurrentState();
  107.  
  108.     ResourceManager< Script > *GetScriptManager();
  109.  
  110.     Input *GetInput();
  111.     Network *GetNetwork();
  112.     SoundSystem *GetSoundSystem();
  113.  
  114. private:
  115.     bool m_loaded; // Indicates if the engine is loading.
  116.     HWND m_window; // Main window handle.
  117.     bool m_deactive; // Indicates if the application is active or not.
  118.  
  119.     EngineSetup *m_setup; // Copy of the engine setup structure.
  120.     IDirect3DDevice9 *m_device; // Direct3D device interface.
  121.     D3DDISPLAYMODE m_displayMode; // Display mode of the current Direct3D device.
  122.     ID3DXSprite *m_sprite; // Sprite interface for rendering 2D textured primitives.
  123.     unsigned char m_currentBackBuffer; // Keeps track of which back buffer is at the front of the swap chain.
  124.  
  125.     LinkedList< State > *m_states; // Linked list of states.
  126.     State *m_currentState; // Pointer to the current state.
  127.     bool m_stateChanged; // Indicates if the state changed in the current frame.
  128.  
  129.     ResourceManager< Script > *m_scriptManager; // Script manager.
  130.  
  131.     Input *m_input; // Input object.
  132.     Network *m_network; // Network object.
  133.     SoundSystem *m_soundSystem; // Sound system.
  134. };
  135.  
  136. //-----------------------------------------------------------------------------
  137. // Externals
  138. //-----------------------------------------------------------------------------
  139. extern Engine *g_engine;
  140.  
  141. #endif